﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script src="../js/jquery-3.2.1.js"></script>
        <script language="javascript" type="text/javascript">
            $.ajax({
                url: "/selectAllModules",
                type: "post",
                success: function (result) {
                    console.log(result)

                    if (result.indexOf("角色管理") == -1) {
                        document.getElementById("lia1").style.display = "none"
                    }
                    if (result.indexOf("管理员管理") == -1) {
                        document.getElementById("lia2").style.display = "none"
                    }
                    if (result.indexOf("资费管理") == -1) {
                        document.getElementById("lia3").style.display = "none"
                    }
                    if (result.indexOf("账务账号管理") == -1) {
                        document.getElementById("lia4").style.display = "none"
                    }
                    if (result.indexOf("业务账号管理") ==-1) {
                        document.getElementById("lia5").style.display = "none"
                    }
                    if (result.indexOf("账单管理") ==-1) {
                        document.getElementById("lia6").style.display = "none"
                    }
                    if (result.indexOf("报表管理") == -1) {
                        document.getElementById("lia7").style.display = "none"
                    }
                }
            });

            //保存结果的提示
            function showResult() {
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
                var bd = $("#baseduration").val();
                var bc = $("#basecost").val();
                var uc = $("#unitcost").val();
                if ($("input:radio:checked").val()=="月"){
                    bd=0;
                    uc=0;
                }
                if ($("input:radio:checked").val()=="计"){
                    bd=0;
                    bc=0;
                }
                $.ajax({
                    url: "/upbyid",
                    type: "post",
                    data: {
                        costid: $("#costid").val(),
                        costname: $("#costname").val(),
                        radFeeType: $("input:radio:checked").val(),
                        baseduration: bd,
                        basecost: bc,
                        unitcost: uc,
                        descr: $("#descr").val(),
                    },
                    success:function () {
                        window.location.href = "/fee";
                    }
                })
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }

            //切换资费类型
            function feeTypeChange(type) {
                var inputArray = document.getElementById("main").getElementsByTagName("input");
                if (type == 1) {
                    inputArray[5].readOnly = true;
                    inputArray[5].value = "";
                    inputArray[5].className += " readonly";
                    inputArray[6].readOnly = false;
                    inputArray[6].className = "width100";
                    inputArray[7].readOnly = true;
                    inputArray[7].className += " readonly";
                    inputArray[7].value = "";
                }
                else if (type == 2) {
                    inputArray[5].readOnly = false;
                    inputArray[5].className = "width100";
                    inputArray[6].readOnly = false;
                    inputArray[6].className = "width100";
                    inputArray[7].readOnly = false;
                    inputArray[7].className = "width100";
                }
                else if (type == 3) {
                    inputArray[5].readOnly = true;
                    inputArray[5].value = "";
                    inputArray[5].className += " readonly";
                    inputArray[6].readOnly = true;
                    inputArray[6].value = "";
                    inputArray[6].className += " readonly";
                    inputArray[7].readOnly = false;
                    inputArray[7].className = "width100";
                }
            }
            urlinfo=window.location.href; //获取当前页面的url
            len=urlinfo.length;//获取url的长度
            offset=urlinfo.indexOf("?");//设置参数字符串开始的位置
            newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
            newsids=newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割
            newsid=newsids[1];//得到参数值
            newsname=newsids[0];//得到参数名字

            console.log(newsidinfo);

            $.ajax({
                url:"/costbyid?costid="+newsid,
                type:"post",
                success:function (result) {
                    var cost = result;
                    $("#costid").val(cost.costId);
                    $("#costname").val(cost.name);
                    if (cost.costType == "月"){
                        $("#monthly").attr("checked", true);
                    } else if (cost.costType == "时"){
                        $("#timeBased").attr("checked", true);
                    } else if (cost.costType == "套"){
                        $("#package").attr("checked", true);
                    }
                    $("#baseduration").val(cost.baseDuration);
                    $("#basecost").val(cost.baseCost);
                    $("#unitcost").val(cost.unitCost);
                    $("#descr").val(cost.descr);
                }
            })
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="/logout">[退出]</a>
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="../index.html" class="index_off"></a></li>
                <li id="lia1"><a href="rolelist" class="role_off"></a></li>
                <li id="lia2"><a href="adminlist" class="admin_off"></a></li>
                <li id="lia3"><a href="fee" class="fee_on"></a></li>
                <li id="lia4"><a href="accountlist" class="account_off"></a></li>
                <li id="lia5"><a href="servicelist" class="service_off"></a></li>
                <li id="lia6"><a href="bill" class="bill_off"></a></li>
                <li id="lia7"><a href="report" class="report_off"></a></li>
                <li><a href="userinfo" class="information_off"></a></li>
                <li><a href="changepsw" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">
            <div id="save_result_info" class="save_success">保存成功！</div>
            <form action="/insert" method="" class="main_form">
                <div class="text_info clearfix"><span>资费ID：</span></div>
                <div class="input_info"><input type="text" class="readonly" readonly value="" id="costid" name="costid"/></div>
                <div class="text_info clearfix"><span>资费名称：</span></div>
                <div class="input_info">
                    <input type="text" class="width300" value="" id="costname" name="costname"/>
                    <span class="required">*
                    </span>
                    <div class="validate_msg_short">50长度的字母、数字、汉字和下划线的组合</div>
                </div>
                <div class="text_info clearfix"><span>资费类型：</span></div>
                <div class="input_info fee_type">
                    <input type="radio" name="radFeeType" id="monthly" onclick="feeTypeChange(1);" value="月"/>
                    <label for="monthly">包月</label>
                    <input type="radio" name="radFeeType" checked="checked" id="package" onclick="feeTypeChange(2);" value="套"/>
                    <label for="package">套餐</label>
                    <input type="radio" name="radFeeType" id="timeBased" onclick="feeTypeChange(3);" value="计"/>
                    <label for="timeBased">计时</label>
                </div>
                <div class="text_info clearfix"><span>基本时长：</span></div>
                <div class="input_info">
                    <input type="text" value="" class="width100" id="baseduration" name="baseduration"/>
                    <span class="info">小时</span>
                    <span class="required">*</span>
                    <div class="validate_msg_long">1-600之间的整数</div>
                </div>
                <div class="text_info clearfix"><span>基本费用：</span></div>
                <div class="input_info">
                    <input type="text" value="" class="width100" id="basecost" name="basecost"/>
                    <span class="info">元</span>
                    <span class="required">*</span>
                    <div class="validate_msg_long">0-99999.99之间的数值</div>
                </div>
                <div class="text_info clearfix"><span>单位费用：</span></div>
                <div class="input_info">
                    <input type="text" value="" class="width100" id="unitcost" name="unitcost"/>
                    <span class="info">元/小时</span>
                    <span class="required">*</span>
                    <div class="validate_msg_long">0-99999.99之间的数值</div>
                </div>
                <div class="text_info clearfix"><span>资费说明：</span></div>
                <div class="input_info_high">
                    <textarea class="width300 height70" id="descr" name="descr">
                    </textarea>
                    <div class="validate_msg_short">100长度的字母、数字、汉字和下划线的组合</div>
                </div>
                <div class="button_info clearfix">
                    <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                    <input type="button" value="取消" class="btn_save" onclick="location.href='/fee'"/>
                </div>
            </form>
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)云科技有限公司 </span>
        </div>
    </body>

</html>
